/**
 * 
 */
package br.ufal.ic.sd.project.server.services;

import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;

import br.ufal.ic.sd.project.server.core.Channel;
import br.ufal.ic.sd.project.server.core.Server;
import br.ufal.ic.sd.project.server.core.ServerService;
import br.ufal.ic.sd.project.server.core.TokenListener;
import br.ufal.ic.sd.project.server.singleton.ServerToken;

/**
 * @author keven andrade
 *
 */
public class TokenService extends ServerService{

    public void executeService(Server objServer) {
	
	String strNextTokken = objServer.getObjChannel().read();
	System.out.println(strNextTokken);
	
	try {
	    objServer.getObjChannel().getObjClientSocket().close();
	} catch (IOException e1) {
	    e1.printStackTrace();
	}
	
	try {
	    if(strNextTokken.equals(InetAddress.getLocalHost().getCanonicalHostName() + ":" + objServer.getObjChannel().getIntPort())){
		objServer.getObjTokenListener().notifyTokensOn();
	    }
	} catch (UnknownHostException e) {
	    e.printStackTrace();
	}
    }

}
